import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './routes'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

const whiteList = ['/login']

const token = localStorage.getItem('token')
console.log(token,'token');

router.beforeEach((to,form,next)=>{
   if (whiteList.indexOf(to.path) !== -1) {
    next()
  } else {
    // 如果用户没有token，则跳转到登录页面
    if (!token) {
      next('/login')
    } else {
      // 如果用户有token，则继续当前的导航
      next()
    }
  }
})


export default router

